/* eslint-disable no-undef */
import hotReload from '@/utils/hotReload'
hotReload()
// const getBookmarks = () => {
//     console.log(chrome)
//     chrome.bookmarks.getTree((tree) => {
//         console.log('标签树', tree)
//         chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
//             console.log('tab', tabs)
//             chrome.tabs.sendMessage(tabs[0].id, { greeting: "hello" }, (response) => {
//                 console.log('response', response)
//                 //   console.log(response.farewell);
//             });
//         });
//     })
// }
// getBookmarks()

const init = () => {
    chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
        console.log('background', request, sender, sendResponse)
        // sendResponse({status:'ok'})
        if (request.order && request.order === 'getBookmarks') {
            // 获取书签
            chrome.bookmarks.getTree((tree) => {
                chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
                    console.log('tab', tabs)
                    // chrome.tabs.connect(tabs[0].id, {
                    //     data: tree
                    // }).postMessage({
                    //     code: 'openLoginAlert'
                    // });
                    chrome.tabs.sendMessage(tabs[0].id, { bookmarks: tree });
                });
            })

        }
    })
}
init()